<title>银行账号</title>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab-content">
            <div class="layui-btn-group demoTable lay-mb15">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
                    <div class="layui-form-item" style="margin:0;">
                        <div class="layui-form-item" style="margin:0;">
                            <div class="layui-inline">
                                <label class="layui-form-label">商户ID</label>
                                <div class="layui-input-block">
                                    <input type="text" name="mchId" id="mchId" placeholder="商户ID" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">账号</label>
                                <div class="layui-input-block">
                                    <input type="text" name="accountNo" id="accountNo" placeholder="账号" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">账号类型</label>
                                <div class="layui-input-block">
                                    <select name="accountType" id="accountType" lay-search="">
                                        <option value="-99">请选择账号类型</option>
                                        <option value="1">银行账号</option>
                                        <option value="2">支付宝账号</option>
                                        <option value="3">微信账号</option>

                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button id="search" class="layui-btn layuiadmin-btn-admin" data-type="reload">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">

                    <!--<button id="addChannelMch" class="layui-btn layui-btn-normal" data-type="add"><i class="layui-icon"></i>添加-->
                    <!--</button>-->
                    <!--<button id= "output" class="layui-btn layui-btn-warm" data-type="output"><i class="layui-icon layui-icon-download-circle"></i>导出-->
                    <!--</button>-->
                    <!--<button id= "batchdel" class="layui-btn layui-btn-danger" data-type="batchdel"><i class="layui-icon"></i>删除-->
                    <!--</button>-->
                </div>
                <table id="bankList" lay-filter="bankList"></table>
            </div>
        </div>
    </div>
</div>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
<script>

    layui.use(['admin','table','util','admin','form'], function(){
        var table = layui.table
        ,$ = layui.$
        ,form = layui.form
        ,admin = layui.admin
        ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        var tplTitle = function(d){
            return '<a class="layui-btn layui-btn-xs" lay-event="edit" >修改</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>'
        };

        table.render({
            elem: '#bankList'
            ,url: layui.setter.baseUrl + '/bank_account/list'
            ,where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            ,id: 'tableReload'
            ,cols: [[
                {field:'mchId', title: '商户ID' }
                ,{field: 'accountType',title: '账号类型', templet: '<div>{{ d.accountType == 1?"银行账号":d.accountType == 2?"支付宝账号":"微信账号" }}</div>'}
                ,{field: 'bankName',title: '银行名称'}
                ,{field: 'accountName',title: '账号姓名'}
                ,{field: 'accountNo', width: 200, title: '账号'}
                ,{field:'createTime', width: 200, title: '创建时间', templet: '<div>{{ layui.util.toDateString(d.createTime) }}</div>' }
                ,{field:'edit', title: '操作', templet: tplTitle }
            ]]
            ,page: true
            ,skin: 'line'
        });

        //监听工具条
        table.on('tool(bankList)', function(obj){
            var data = obj.data;
            var layEvent = obj.event;

            if(layEvent === 'edit'){ //编辑
                location.hash="/merchant/bank/update/id=" + data.id + "/accountNo=" + data.accountNo;
            } else if(obj.event === 'del'){
                layer.confirm('确认删除么', function(index){
                    admin.req({
                        type: 'get',
                        url: layui.setter.baseUrl + '/bank_account/delete',
                        data: {
                            id: data.id,
                        },
                        success: function(res){
                            if(res.code == 0) {
                                layer.msg('删除成功', {
                                    icon: 1
                                });
                                table.reload("tableReload");
                            }
                        }
                    });
                });
            }
        });

        // 搜索
        var $ = layui.$, active = {
            reload: function(){
                var accountNo = $('#accountNo').val();
                var mchId = $("#mchId").val();
                var accountType = $("#accountType").val();
                //执行重载
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        accountNo: accountNo,
                        mchId : mchId,
                        accountType : accountType
                    }
                });
            }
        };
        $('#search').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        // 渲染表单
        form.render();

    })

    
</script>